<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 报名--->学习--->简历---->面试---->上班

        // 终极解决方案
        // 将函数设置成一个async函数 - 可以在内部写 await 同步执行的函数！
        async function fn() {
            // await 获取promise成功的结果值
            // await 右侧可以是一个promise - 会返回成功的结果值! 不会返回失败的结果值
            try {
                let res = await new Promise((resolve, reject) => {
                    setTimeout(() => {
                        resolve("报名成功");
                        // reject('失败');
                    }, 1000)
                })
                console.log(res);
                let res2 = await new Promise((resolve, reject) => {
                    setTimeout(() => {
                        // resolve("学习");
                        reject('失败')
                    }, 1000)
                })
                console.log(res2);
                let res3 = await new Promise((resolve, reject) => {
                    setTimeout(() => {
                        resolve("整理简历");
                    }, 1000)
                })
                console.log(res3);
                let res4 = await new Promise((resolve, reject) => {
                    setTimeout(() => {
                        resolve("入职成功");
                    }, 1000)
                })
                console.log(res4);
            }catch(err){
                console.log(err);
            }
        }

        fn();



    </script>
</body>

</html>